package cn.ad.server.web.filter.bid;

import cn.ad.server.web.spring.service.actions.context.BidContext;
import cn.ad.server.domain.ad.Strategy;

import java.util.List;

/**
 * 地域定向
 * 
 * @author wangwei
 */
public class GeoTargetMatcher implements BidMatcherChain {

	@Override
	public boolean match(Strategy strategy, BidContext context) {
		List<Integer> geoCitys = strategy.getGeoCityTargert();
		List<Integer> geoCountrys = strategy.getGeoCountryTargert();
		List<Integer> geoDistricts = strategy.getGeoDistrictTargert();
		List<Integer> geoStates = strategy.getGeoStateTargert();
		if ((geoCitys != null && geoCitys.size() > 0) && geoCitys.contains(context.getCityId())) {
			return true;
		}
		if ((geoCountrys != null && geoCountrys.size() > 0) && geoCountrys.contains(context.getCountryId())) {
			return true;
		}
		if ((geoDistricts != null && geoDistricts.size() > 0) && geoDistricts.contains(context.getDistrictId())) {
			return true;
		}
		if ((geoStates != null && geoStates.size() > 0) && geoStates.contains(context.getStateId())) {
			return true;
		}
		if ((geoCitys == null || geoCitys.size() == 0) && (geoCountrys == null || geoCountrys.size() == 0)
				&& (geoDistricts == null || geoDistricts.size() == 0) && (geoStates == null || geoStates.size() == 0)) {
			return true;
		}
		return false;
	}
	
}
